package com.yuda.campsite.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuda.common.log.annotation.Log;
import com.yuda.common.log.enums.BusinessType;
import com.yuda.common.security.annotation.PreAuthorize;
import com.yuda.campsite.domain.CampsiteWorkStudent;
import com.yuda.campsite.service.ICampsiteWorkStudentService;
import com.yuda.common.core.web.controller.BaseController;
import com.yuda.common.core.web.domain.AjaxResult;
import com.yuda.common.core.utils.poi.ExcelUtil;
import com.yuda.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author wyn
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/student")
public class CampsiteWorkStudentController extends BaseController
{
    @Autowired
    private ICampsiteWorkStudentService campsiteWorkStudentService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "common:student:list")
    @GetMapping("/list")
    public TableDataInfo list(CampsiteWorkStudent campsiteWorkStudent)
    {
        startPage();
        List<CampsiteWorkStudent> list = campsiteWorkStudentService.selectCampsiteWorkStudentList(campsiteWorkStudent);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "common:student:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampsiteWorkStudent campsiteWorkStudent) throws IOException
    {
        List<CampsiteWorkStudent> list = campsiteWorkStudentService.selectCampsiteWorkStudentList(campsiteWorkStudent);
        ExcelUtil<CampsiteWorkStudent> util = new ExcelUtil<CampsiteWorkStudent>(CampsiteWorkStudent.class);
        util.exportExcel(response, list, "student");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "common:student:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(campsiteWorkStudentService.selectCampsiteWorkStudentById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "common:student:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampsiteWorkStudent campsiteWorkStudent)
    {
        /**设置自动填充修改时间，新镇时间只能添加一次*/
        Date date =new Date();
        campsiteWorkStudent.setCreateTime(date);
        campsiteWorkStudent.setUpdateTime(date);
        return toAjax(campsiteWorkStudentService.insertCampsiteWorkStudent(campsiteWorkStudent));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "common:student:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampsiteWorkStudent campsiteWorkStudent)
    {
        /**设置自动填充时间，修改时间*/
        Date date =new Date();
        campsiteWorkStudent.setUpdateTime(date);
        return toAjax(campsiteWorkStudentService.updateCampsiteWorkStudent(campsiteWorkStudent));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "common:student:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(campsiteWorkStudentService.deleteCampsiteWorkStudentByIds(ids));
    }
}
